package com.grouponmall.web;

import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.grouponmall.model.Deal;

/**
 * @author xueqiang.mi
 * 
 */
@Controller
public class DefaultController extends BaseController {

	private static final Integer DEFAULT_PAGE_SIZE = 9;

	@RequestMapping("/cities.htm")
	public String cities(Model model) {
		List<String> cities = dealService.getCities();
		model.addAttribute("cities", cities);
		return "cities";
	}

	@RequestMapping("/deals.htm")
	public String deals(Model model, @RequestParam String city,
			@RequestParam(required = false) Integer index) {
		index = index == null ? 1 : index;
		List<Deal> deals = dealService.getDealsByCity(city, index,
				DEFAULT_PAGE_SIZE);
		model.addAttribute("deals", deals);
		return "deals";
	}

	@RequestMapping("/index.htm")
	public String index(Model model) {
		List<Deal> deals = dealService.getLatestDeals();
		model.addAttribute("deals", deals);
		return "latestDeals";
	}
}
